package com.jy.api.dao;

import com.jy.api.domain.MakeOrder;
import com.jy.api.domain.MakeOrderItem;
import com.jy.api.enums.OrderItemMakeType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface MakeOrderDao extends CrudRepository<MakeOrder, Integer> {



    List<MakeOrder> findAllByStoreIdAndFinishedIsFalseAndCreatorIdAndShowEnabledIsTrueOrderByAddTimeAsc(String storeId, String mobile);


    List<MakeOrder> findAllByStoreIdAndFinishedIsFalseAndShowEnabledIsTrueOrderByAddTimeAsc(String storeId);


    Page<MakeOrder> findAllByStoreIdAndFinishedOrderByAddTimeAsc(String storeId,boolean finished, Pageable pageable);

    Page<MakeOrder> findAllByStoreIdAndFinishedOrderByAddTimeDesc(String storeId,boolean finished, Pageable pageable);

    MakeOrder findByOrderId(String id);
    @Modifying
    @Transactional
    @Query(value = "UPDATE `make_order` set `finished` =1  WHERE  `store_id` =?   AND finished=0 " ,nativeQuery = true)
    void updateAllOrderStatus(String storeId);

}
